package com.mengze.linlee_iot_adnroid.ui.notifications

import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.mengze.linlee_iot_adnroid.R
import com.mengze.linlee_iot_adnroid.databinding.ActivityBlueDeviceListBinding
import com.mengze.linlee_iot_adnroid.databinding.FragmentNotificationsBinding

class NotificationsFragment : Fragment() {

    private lateinit var notificationsViewModel: NotificationsViewModel
    private var _binding: FragmentNotificationsBinding? = null
    private val binding get() = _binding!!

    private fun updateStatusBarAndNavBar( inflater: LayoutInflater, container: ViewGroup?){
        val activity = getActivity();
        // 方法1：直接设置颜色值
        activity?.window?.statusBarColor = Color.parseColor("#FF54D437") // 橙色
        activity?.window.apply {
            var statusBarColor = Color.parseColor("#FF54D437") // 设置颜色
        }

        notificationsViewModel =
            ViewModelProvider(this).get(NotificationsViewModel::class.java)

        _binding = FragmentNotificationsBinding.inflate(inflater, container, false)
        val root: View = binding.root
        binding.toolbarTitle.text = "消息列表"

    }


    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

        updateStatusBarAndNavBar(inflater, container);

        val activity = getActivity();
        // 方法1：直接设置颜色值
        activity?.window?.statusBarColor = Color.parseColor("#FF54D437") // 橙色
        activity?.window.apply {
            var statusBarColor = Color.parseColor("#FF54D437") // 设置颜色
        }

        notificationsViewModel =
            ViewModelProvider(this).get(NotificationsViewModel::class.java)

        _binding = FragmentNotificationsBinding.inflate(inflater, container, false)
        val root: View = binding.root
        binding.toolbarTitle.text = "消息列表"

        return root
    }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        // 模拟数据
        val messages = listOf(
            Message(1, "系统通知", "您有一条新的系统消息", "2023-05-30 10:00", true),
            Message(2,"活动提醒", "周末特惠活动即将开始", "2023-05-29 15:30", false),
            Message(3,"账户安全", "您的账户有异常登录", "2023-05-28 09:15", true)
        )

        binding?.recyclerView?.layoutManager = LinearLayoutManager(requireContext())
        binding.recyclerView.adapter = MessageAdapter(messages) { item ->
            when (item) {

            }
        }

    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }

}